/**
 * 
 */
package scriptrunner.execution;

import java.io.Serializable;

/**
 * @author Administrator
 * 
 */
public class LHListAccess extends LeftHandSideExpr implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1950978879480494975L;
	
	/**
	 * @param lhsn
	 * @param ee
	 */
	public LHListAccess(LHListName lhsn, EvaluateExpr ee) {
		this.lhsn = lhsn;
		this.ee = ee;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * scriptrunner.execution.LeftHandSideExpr#AssignValue(scriptrunner.execution
	 * .EvaluateExpr)
	 */
	@Override
	public void AssignValue(Session se, ValueObject rhs)
			throws ExecuteErrorException {
		ValueListObject listValue = lhsn.GetLHObject(se);
		ValueObject idx = ee.CalculateResult(se);
		try {
			listValue.SetListElement(idx, rhs);
		} catch (CloneNotSupportedException e) {
			throw new ExecuteErrorException(
					"The value cannot be cloned when it is assigned to a varible");
		}
	}

	LHListName lhsn;
	EvaluateExpr ee;
}
